class Solution {
    public double myPow(double x, int n) {
        long N = n;
        return N>0?quickPow(x,N) : 1.0/quickPow(x,-N);
    }
    private double quickPow(double x,long N) {
        if(0 == N) {
            return 1.0;
        }
        double ans = 1.0;
        double base = x;
        while(N>0) {
            if(1 == N%2) {
                ans*=base;
            }
            base*=base;
            N = N >> 1;
        }
        return ans;
        
    }
    private double quickPow1(double x,long N) {
        if(0 == N) {
            return 1.0;
        }
        double y = quickPow(x,N>>1);
        return N%2 == 0 ? y*y:y*y*x;
    }
}